package com.it.App.vo;

import lombok.Data;

/**
 * TODO
 *
 * @author: Coke
 * @DateTime: 2023/11/18/21:21
 **/
@Data
public class Response<T> {
    
    /**
     * 结果
     *
     * @mock true
     */
    private boolean success;
    
    /**
     * 状态码
     *
     * @mock 200
     */
    private int code;
    
    /**
     * 消息提示
     *
     * @mock 操作成功
     */
    
    private String msg;
    
    /**
     * 结果体
     *
     * @mock null
     */
    private T data;
    
    public Response () {
    
    }
    
    public Response (int code, Object status) {
        super();
        this.code = code;
        this.msg = status.toString();
        if (code == 1) {
            this.success = true;
        } else {
            this.success = false;
        }
    }
    
    public Response (int code, String status, T result) {
        super();
        this.code = code;
        this.msg = status;
        this.data = result;
        if (code == 1) {
            this.success = true;
        } else {
            this.success = false;
        }
    }
    
    public static Response<?> ok() {
        return new Response<>(1, "success");
    }
    
    public static <T> Response<T> ok(T t) {
        return new Response<T>(1, "success", t);
    }
    
    public static Response<?> error(String status) {
        return new Response<>(500, status);
    }
    
    public static Response<?> error(int code, String status) {
        return new Response<>(code, status);
    }
}
